package com.ssm.converter;


import org.springframework.core.convert.converter.Converter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: exercise1_online_shopping
 * @author: qin haojun
 * @create: 2021-02-16 18:51
 */
public class BooleanConverter implements Converter<String, Boolean> {

    @Override
    public Boolean convert(String source) {
        // 判断
        if(source == null){
            //抛出运行异常
            throw new RuntimeException("请您传入数据");
        }
        if(!(source.equals("true")&&source.equals("false"))){
            throw new RuntimeException("传输数据有误");
        }

        return Boolean.parseBoolean(source);
    }

}
